<template>
  <div class="main-info">
    <!-- <div class="bar">
      <img
        src="../../../../assets/images/datav/record.png"
        class="bar-history"
        @click="onRecord"
      />
    </div> -->
    <div class="table-header">
      <div class="table-header-type">类型</div>
      <div class="table-header-item">时间</div>
      <div class="table-header-item">设备编码</div>
      <div class="table-header-item">安装点</div>
      <div class="table-header-item">状态</div>
      <div class="table-header-item-btn">操作</div>
    </div>

    <div class="table-body">
      <div class="table-body-icon">
        <img
          src="../../../../assets/images/datav/relative1.png"
          class="ball-position"
        />
        <img
          src="../../../../assets/images/datav/relative.png"
          class="relative"
        />
        <div class="table-item-fire">火情</div>
      </div>
      <div class="table-body-box" v-if="alarmData && alarmData.length">
        <div
          class="item-wrap"
          v-for="item in alarmData"
          :key="item.id"
          :style="{ opacity: item.status == 3 ? '0.5' : '1' }"
        >
          <div class="table-body-item">{{ item.createTime }}</div>
          <div class="table-body-item">{{ item.imei }}</div>
          <div class="table-body-item">{{ item.name }}</div>
          <div class="table-body-item">
            <span v-if="item.status == 1">未处理</span>
            <span v-else-if="item.status == 2">处理中</span>
            <span v-else-if="item.status == 3">已处理</span>
          </div>
          <div class="table-body-item-btn">
            <span class="btn-view" @click="onEetails(item, '火情')">查看</span>
          </div>
        </div>
      </div>
      <div class="table-body-box" v-else>
        <div class="none-data">暂无数据</div>
      </div>
    </div>

    <div class="table-body">
      <div class="table-body-icon">
        <img
          src="../../../../assets/images/datav/relative3.png"
          class="ball-position"
        />
        <img
          src="../../../../assets/images/datav/relative.png"
          class="relative"
        />
        <div class="table-item-fire" style="color: #feb201">故障</div>
      </div>
      <div
        class="table-body-box"
        v-if="hiddenDangerData && hiddenDangerData.length"
      >
        <div
          class="item-wrap"
          v-for="item in hiddenDangerData"
          :key="item.id"
          :style="{
            opacity: item.status == 2 || item.status == 4 ? '0.5' : '1',
            backgroundImage: `url(${require('@/assets/images/datav/firebg2.png')}`,
          }"
        >
          <div class="table-body-item">{{ item.createTime }}</div>
          <div class="table-body-item">{{ item.imei }}</div>
          <div class="table-body-item">{{ item.spaceName }}</div>
          <div class="table-body-item">
            <span v-if="item.status == 1">未处理</span>
            <span v-else-if="item.status == 2">已忽略</span>
            <span v-else-if="item.status == 3">修复中</span>
            <span v-else-if="item.status == 4">已修复</span>
          </div>
          <div class="table-body-item-btn">
            <span class="btn-view btn-view2" @click="onEetails(item, '故障')"
              >查看</span
            >
          </div>
        </div>
      </div>
      <div class="table-body-box" v-else>
        <div class="none-data">暂无数据</div>
      </div>
    </div>

    <div class="table-body">
      <div class="table-body-icon">
        <img
          src="../../../../assets/images/datav/relative2.png"
          class="ball-position"
        />
        <img
          src="../../../../assets/images/datav/relative.png"
          class="relative"
        />
        <div class="table-item-fire" style="color: #9397fc">反馈</div>
      </div>
      <div class="table-body-box" v-if="feedbackData && feedbackData.length">
        <div
          class="item-wrap"
          v-for="item in feedbackData"
          :key="item.id"
          :style="{
            opacity: item.status == 2 || item.status == 4 ? '0.5' : '1',
            backgroundImage: `url(${require('@/assets/images/datav/firebg.png')}`,
          }"
        >
          <div class="table-body-item">{{ item.createTime }}</div>
          <div class="table-body-item">{{ item.deviceCode }}</div>
          <div class="table-body-item">{{ item.spaceName }}</div>
          <div class="table-body-item">
            <span v-if="item.status == 1">未处理</span>
            <span v-else-if="item.status == 2">处理中</span>
            <span v-else-if="item.status == 3">已处理</span>
          </div>
          <div class="table-body-item-btn">
            <span class="btn-view btn-view3" @click="onEetails(item, '反馈')"
              >查看</span
            >
          </div>
        </div>
      </div>
      <div class="table-body-box" v-else>
        <div class="none-data">暂无数据</div>
      </div>
    </div>
    <div class="auto">
      <div class="auto-mode">
        <!-- <div class="sound-suppression"><i class="iconfont huatong1"></i>消音</div>
      <div class="resttiong"><i class="iconfont huatong1"></i>复位</div>
      <div class="operation-mode">一键报警</div> -->
        <div
          class="sound-suppression"
          v-for="item in b_panic"
          :key="item.id"
          @click="onCommand(item)"
        >
          {{ item.keyName }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  reqAlarmList,
  reqHiddenDangerPage,
  reqFeedbackPage,
  reqProductList,
  reqDetectorProductList,
} from "@/api/api";
import { mapState } from "vuex";

import mqtt from "mqtt"; //index.html引入的已弃用
import { reqClient } from "@api/apiDatav.js";
export default {
  props: ["fcInfo", "b_panic", "deviceCode", "Info_mqtt"],
  components: {},
  data() {
    return {
      page: 1, //页码
      limit: 10, //每页条数
      total: 0, //总条数
      loadingTable: false, //表格loading
      alarmData: [], //告警列表
      hiddenDangerData: [], //隐患列表
      feedbackData: [], //反馈列表
    };
  },
  computed: {
    ...mapState(["datav", "user"]),
  },
  watch: {
    Info_mqtt: {
      handler(val) {
        if (val.dataType == 1) {
          this.alarmData.unshift(val);
          if (this.alarmData.length > 50) {
            this.alarmData.splice(0, 20);
          }
        } else if (val.dataType == 2) {
          this.hiddenDangerData.unshift(val);
          if (this.hiddenDangerData.length > 50) {
            this.hiddenDangerData.splice(0, 20);
          }
        } else if (val.dataType == 3) {
          this.feedbackData.unshift(val);
          if (this.feedbackData.length > 50) {
            this.feedbackData.splice(0, 20);
          }
        }
      },
      deep: true,
    },
  },
  created() {},
  async mounted() {},
  methods: {
    async getData() {
      // if (!this.fcInfo.id) {
      //   this.$watch("fcInfo", (newVal) => {
      //     //  子组件检测到数据更新
      //     this.getAlarmList();
      //     this.getHiddenDangerList();
      //     this.getFeedbackList();
      //   });
      // } else {
      //   this.getAlarmList();
      //   this.getHiddenDangerList();
      //   this.getFeedbackList();
      // }
      this.getAlarmList();
      this.getHiddenDangerList();
      this.getFeedbackList();
    },
    onRecord() {
      this.$parent.onRecord();
    },
    onEetails(data, name) {
      this.$parent.onEetails(data, name);
    },
    // 下发指令
    async onCommand(item) {
      this.$parent.onCommand(item);
    },
    // 获取告警列表
    async getAlarmList() {
      let res = await reqAlarmList(this.page, this.limit, {
        userId: this.user.userId,
        roleName: this.user.roleName,
        tenantId: this.user.tenantId,
        orgId: this.fcInfo.orgId, //机构||单位
        imei: this.deviceCode,
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);

      this.total = res.data.total || 0;
      this.alarmData = res.data.rows || [];
    },
    // 获取隐患列表
    async getHiddenDangerList() {
      this.loadingTable = true;
      let res = await reqHiddenDangerPage(this.page, this.limit, {
        userId: this.user.userId,
        roleName: this.user.roleName,
        orgId: this.fcInfo.orgId, //机构||单位
        imei: this.deviceCode,
      });
      this.loadingTable = false;
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);

      this.total = res.data.total || 0;
      this.hiddenDangerData = res.data.rows || [];
    },
    // 获取反馈列表
    async getFeedbackList() {
      this.loadingTable = true;
      let res = await reqFeedbackPage(this.page, this.limit, {
        userId: this.user.userId,
        tenantId: this.user.tenantId,
        roleName: this.user.roleName,
        orgId: this.fcInfo.orgId, //机构||单位
        deviceCode: this.deviceCode,
      });
      this.loadingTable = false;
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);

      this.total = res.data.total || 0;
      this.feedbackData = res.data.rows || [];
    },
  },
};
</script>

<style lang="less" scoped>
.fontSize (@px, @attr: font-size) {
  @vw: (@px / 1920) * 100;
  @{attr}: ~"@{vw}vw";
}
.width (@px, @attr: width) {
  @vw: (@px / 1920) * 100;
  @{attr}: ~"@{vw}vw";
}
.height (@px, @attr: height) {
  @vh: (@px / 1080) * 100;
  @{attr}: ~"@{vh}vh";
}
.lineHeight (@px, @attr: line-height) {
  @vh: (@px / 1080) * 100;
  @{attr}: ~"@{vh}vh";
}
.marginTop (@px, @attr: margin-top) {
  @vh: (@px / 1080) * 100;
  @{attr}: ~"@{vh}vh";
}
.marginLeft (@px, @attr: margin-left) {
  @vw: (@px / 1920) * 100;
  @{attr}: ~"@{vw}vw";
}
.marginRight (@px, @attr: margin-right) {
  @vw: (@px / 1920) * 100;
  @{attr}: ~"@{vw}vw";
}
.marginBottom (@px, @attr: margin-bottom) {
  @vh: (@px / 1080) * 100;
  @{attr}: ~"@{vh}vh";
}
.paddingLeft (@px, @attr: padding-left) {
  @vw: (@px / 1920) * 100;
  @{attr}: ~"@{vw}vw";
}

.main-info {
  .fontSize(14);
  padding: 0 1vw 0.5vw 1vw;
  position: relative;
  .bar {
    text-align: right;
    .bar-history {
      .width(120);
      cursor: pointer;
    }
  }
  .table-header {
    background: rgba(60, 84, 139, 0.8);
    border-radius: 5px 5px 5px 5px;
    border: 1px solid #4a6aa8;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    .marginTop(10);
    .table-header-type {
      .width(130);
      text-align: center;
    }
    .table-header-item {
      .width(160);
      text-align: left;
      padding-right: 4px;
    }
    .table-header-item-btn {
      flex: 1;
      text-align: right;
      white-space: nowrap;
      padding-right: 18px;
    }
  }
  .table-body {
    width: 100%;
    .height(110);
    position: relative;
    .marginTop(15);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    color: #fff;
    .table-body-icon {
      .width(130);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .ball-position {
        position: absolute;
        top: 4px;
        z-index: 1;
        width: 51px;
        height: 51px;
      }
      .relative {
        width: 51px;
        height: 51px;
        position: relative;
      }
      .table-item-fire {
        font-family: monospace;
        font-weight: 600;
        color: #fa5a63;
        .fontSize(14);
        width: 61px;
        text-align: center;
      }
    }
    .table-body-box {
      overflow-y: auto;
      flex: 1;
      height: 100%;
      .fontSize(12);
      .item-wrap {
        .height(32);
        border-radius: 5px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        flex-direction: row;
        margin-bottom: 4px;
        background: url("../../../../assets/images/datav/firebg3.png") 0px 0px
          no-repeat;
        background-size: 100% 100%;
        .table-body-item {
          .width(160);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          padding-right: 4px;
        }
        .table-body-item-btn {
          flex: 1;
          text-align: right;
          white-space: nowrap;
          padding-right: 16px;
          .btn-view {
            background: linear-gradient(
              90deg,
              rgba(216, 76, 111, 0.35) 0%,
              rgba(216, 76, 111, 0.35) 100%
            );
            box-shadow: inset 0px 3px 10px 1px rgba(191, 58, 91, 0.47);
            border-radius: 2px 2px 2px 2px;
            border: 1px solid #fa4f59;
            padding: 1px 4px;
            cursor: pointer;
          }
          .btn-view2 {
            background: linear-gradient(
              90deg,
              rgba(234, 164, 39, 0.35) 0%,
              rgba(245, 141, 19, 0.35) 100%
            );
            box-shadow: inset 0px 3px 10px 1px rgba(234, 164, 39, 0.47);
            border-radius: 2px 2px 2px 2px;
            border: 1px solid #eaa427;
          }
          .btn-view3 {
            background: linear-gradient(
              90deg,
              rgba(147, 151, 252, 0.35) 0%,
              rgba(147, 151, 252, 0.35) 100%
            );
            box-shadow: inset 0px 3px 10px 1px rgba(147, 151, 252, 0.47);
            border-radius: 2px 2px 2px 2px;
            border: 1px solid #9397fc;
          }
        }
      }
    }
    .none-data {
      height: 100%;
      opacity: 0.5;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .auto {
    .marginTop(15);
    // .marginLeft(50);
    // .paddingLeft(50);
    // box-sizing: border-box;
    .fontSize(14);
    .height(60);
    overflow-x: auto;
    color: #d2e1fe;
    width: 100%;
    white-space: nowrap;
    overflow-y: hidden;
  }

  .auto-mode {
    display: flex;
    flex-wrap: nowrap; /* 关键：禁止换行 */
    min-width: min-content; /* 确保内容不压缩 */

    .sound-suppression {
      .width(205);
      .height(40);
      // .lineHeight(40);
      background: #5179cb;
      box-shadow: 0px 0px 10px 1px #5482cc;
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #78a0f0;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      .marginRight(20);
      // .marginBottom(20);
    }
    .resttiong {
      margin-left: 15px;
      .width(220);
      .height(40);
      background: rgba(60, 84, 139, 0.4);
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #6084cc;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }
    .operation-mode {
      margin-left: 35px;
      background: url("../../../../assets/images/datav/alarm.png") center 2px
        no-repeat;
      background-size: 100% 100%;
      .width(180);
      .height(75);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }
  }
}
::v-deep .auto::-webkit-scrollbar {
  display: block; //显示滚动条
  width: 0px; //定义滚动条宽度
  height: 6px; //定义滚动条高度
  border-radius: 10px; //定义滚动条圆角
  // margin-bottom: 10px;
}
/*定义滚动条轨道 内阴影+圆角*/
::v-deep .auto::-webkit-scrollbar-track {
  box-shadow: inset 0 0 0px rgba(240, 240, 240, 0.5); //定义轨道阴影
  border-radius: 10px; //定义轨道圆角
  background-color: transparent; //定义轨道颜色
}

/*定义滑块 内阴影+圆角*/
::v-deep .auto::-webkit-scrollbar-thumb {
  border-radius: 10px; //定义滑块圆角
  box-shadow: inset 0 0 0px rgba(240, 240, 240, 0.5); //定义滑块阴影
  background-color: #5179cb; //定义滑块颜色
}
</style>
